<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>登录</title>
    <link rel="stylesheet" href="../assets/vendors/bootstrap/css/bootstrap.css">
    <link rel="stylesheet" href="../assets/css/admin.css">
</head>

<body>
    <div class="login">
        <div class="login-wrap">
            <img src="../uploads/default.png" alt="" class="avatar">
            <div class="form-group">
                <label for="email" class="sr-only">邮箱</label>
                <input type="email" id="email" class="form-control" placeholder="邮箱" autofocus>
            </div>
            <div class="form-group">
                <label for="password" class="sr-only">密码</label>
                <input type="password" id="password" class="form-control" placeholder="邮箱">
            </div>
            <button class="btn btn-primary btn-block login-btn">登 录</button>
        </div>
    </div>
</body>
@@include('../common/base.html')

<script>
    $('.login-btn').click(function () {

        const email = $('#email').val()
        const pwd = $('#password').val()

        if (email && !email.trim()) {
            alert('请输入邮箱')
            return
        }

        if (pwd && !pwd.trim()) {
            alert('请输入密码')
            return
        }

        const params = {
            email,
            password: pwd
        }

        $.ajax({
            url: `${baseUrl}/login`,
            type: 'post',
            data: params,
            success: function (result) {
                const token = result.token
                if (token) {
                    localStorage.setItem('token', token)
                    location.href = './index.html'
                } else {
                    alert('登录失败')
                }
            },
            error: function (err) {
                console.log('登录失败：', err);
            }
        })
    })



</script>

</html>